package com.zt.rongda.asset.service;

import java.util.List;

import com.zt.rongda.asset.inter.AssetTransferMapper;
import com.zt.rongda.asset.model.AssetTransfer;
import com.zt.system.model.BusinessException;
import com.zt.servlet.ReqBean;
import com.zt.system.model.SqlBuilder;
import com.zt.system.service.BaseService;
import com.zt.util.StringUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class AssetTransferService extends BaseService {

    @Autowired
    private AssetTransferMapper assetTransferMapper;

    /**
    * 查询
    *
    * @param reqBean
    * @return
    */
    public JSONObject getTable(ReqBean reqBean) {
        SqlBuilder sqlBuilder = new SqlBuilder("");
        sqlBuilder.appendSql("select * from ASSET_TRANSFER where 1=1 ");
        sqlBuilder.addWhere("ASSET_ID", reqBean.getInfo("assetId"));
        return queryTable(sqlBuilder, reqBean.getPageSize(), reqBean.getPageIndex());
    }

    /**
    * 通过id查询
    *
    * @param listId
    * @return
    */
    public AssetTransfer getById(String listId) {
        return assetTransferMapper.selectByPrimaryKey(listId);
    }

    /**
    * 新增
    *
    * @param assetTransfer
    */
    public void add(AssetTransfer assetTransfer) {
        assetTransfer.setListId(stringId());// 手动设置Id

        assetTransfer.setMakeTime(new Date());
        assetTransfer.setModifyTime(assetTransfer.getMakeTime());
        assetTransferMapper.insert(assetTransfer);
    }

    /**
    * 修改
    *
    * @param assetTransfer
    */
    public void update(AssetTransfer assetTransfer) {
        String assetId = assetTransfer.getAssetId();
        if (StringUtil.isEmpty(assetId)) {
            throw new BusinessException("获取主键失败");
        }

        assetTransfer.setModifyTime(new Date());
        assetTransferMapper.updateByPrimaryKeySelective(assetTransfer);
    }

    /**
    * 删除
    *
    * @param assetId
    */
    public void delete(String assetId) {
        if (StringUtil.isEmpty(assetId)) {
            throw new BusinessException("获取主键失败");
        }
        assetTransferMapper.deleteByPrimaryKey(assetId);
    }

}